package com.corot.codoc.bean;

import com.corot.core.model.entity.BaseEntity;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.util.Date;

/**
 * 实现自动补齐默认del_flag
 *
 * @author leesir
 */
@MappedSuperclass
public class BaseData extends BaseEntity{
    protected Date createTime;
    protected Date updateTime;

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    @PrePersist
    public void beforeSave(){
        Date date = new Date();
        this.createTime = date;
        this.updateTime = date;
        this.setDelFlag(BaseEntity.DEL_FLAG_NORMAL);
    }

    @PreUpdate
    public void beforeUpdate(){
        this.updateTime = new Date();
    }
}
